#include "timer.h"

void Timer_Init(void){
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
		
		TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
		TIM_TimeBaseInitStruct.TIM_Prescaler = SystemCoreClock/10000 -1;
		TIM_TimeBaseInitStruct.TIM_Period = 0xFFFF;
		TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
		TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
		TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
	
		TIM_Cmd(TIM2, ENABLE);
}

void delay_ms(uint32_t ms){
		TIM_SetCounter(TIM2,0);//reset
		while (TIM_GetCounter(TIM2)<(10*ms)); 
	}
void delay_s(uint32_t s){
		for(uint32_t i = 0;i<(1000*s); ++i){
		delay_ms(1);
		}

}